package trastienda.servlet.usuario;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import trastienda.dao.UsuarioDAO;
import trastienda.excepcion.DAOExcepcion;
import trastienda.modelo.Usuario;

/**
 * Servlet implementation class for Servlet: UsuarioModificarServlet
 * 
 */
public class UsuarioModificarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public UsuarioModificarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String a = request.getParameter("idUsuario");
		String b = request.getParameter("clave");
		String c = request.getParameter("nombres");
		String d = request.getParameter("paterno");
		String e = request.getParameter("materno");
		String f = request.getParameter("correo");
		String g = request.getParameter("direccion");
		String h = request.getParameter("telefono");
		String i = request.getParameter("estado");

		Usuario vo = new Usuario();
		vo.setIdUsuario(a);
		vo.setClave(b);
		vo.setNombres(c);
		vo.setPaterno(d);
		vo.setMaterno(e);
		vo.setCorreo(f);
		vo.setDireccion(g);
		vo.setTelefono(h);
		vo.setEstado(i);

		UsuarioDAO dao = new UsuarioDAO();
		try {
			dao.actualizar(vo);
			RequestDispatcher rd = request
					.getRequestDispatcher("/usuarioBuscar.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e1) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}

	}
}